import Vue from 'vue'
import App from './App.vue'
//导入框架: vue-router
import router from "./router";
//导入框架: element-ui
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
//导入框架: 粒子特效
import VueParticles from 'vue-particles'

//导入依赖: axios网络请求
import axios from 'axios'
//导入依赖 : 全局样式表
import './assets/css/global.css'


//引用富文本编辑器
import VueQuillEditor from 'vue-quill-editor'
//引入富文本css
// require styles
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import filter from "@/filter/filter";

// 配置请求的根路径
// axios.defaults.baseURL=''

Vue.config.productionTip = false;
Vue.use(ElementUI);
Vue.use(VueParticles);
Vue.prototype.$ajax = axios;//axios通过$ajax全局使用
Vue.use(VueQuillEditor, /* { default global options } */)


axios.defaults.withCredentials = true;

/*
* 全局过滤器
* */

Object.keys(filter).forEach(key =>{
  Vue.filter(key,filter[key])
})

/*
* axios拦截器
* */

axios.interceptors.request.use(function (config){
  console.log("请求:",config);
  return config;
},err=>{});

axios.interceptors.response.use(function (response){
  console.log("返回结果:",response);
  return response;
},err=>{});

// 路由登录拦截
router.beforeEach((to, from, next) => {
  // 要不要对meta.loginRequire属性做监控拦截
  if (to.matched.some(function (item) {
    return item.meta.loginRequire
  })) {
    let loginUser = Tool.getLoginUser();
    if (Tool.isEmpty(loginUser)) {
      next('/login');
    } else {
      next();
    }
  } else {
    next();
  }
});

new Vue({
  router,
  render: h => h(App),
}).$mount('#app')

console.log("环境:",process.env.NODE_ENV);
